package com.aidex.wxCompany;

import com.aidex.wxCompany.WxWrokDomainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/wxwork")
public class WxWorkController {

    private String REBOT_WEB_HOOK = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=ad790f2d-a464-4c74-a1e1-eef53a4b3bf0";

    @Autowired
    private WxWorkService wxWorkService;
    @Autowired
    private WxWrokDomainService wxWrokDomainService;

    @GetMapping("/test")
    public String test() {
        return "test message";
    }

    @GetMapping("/send")
    public String sendMessage() {
        String accessToken = wxWorkService.getAccessToken();
        System.out.println("AccessToken: " + accessToken);
        wxWorkService.sendTextMessage("Lidong", "你有新客户进线，请注意及时跟进");
        return "Message sent successfully";
    }

    // Controller层示例
    @GetMapping("/send-demo")
    public String sendDemo() {
        // 发送文本
        wxWorkService.sendTextMessage("Banson188", "您的订单已发货");

        // 发送Markdown
        wxWorkService.sendMarkdownMessage("Banson188", "服务器CPU使用率超过 **90%**");

        // 发送图文
        wxWorkService.sendNewsMessage(
                "Banson188",
                "新版本发布通知",
                "V2.0版本包含10项功能优化",
                "https://your-domain.com/release-notes",
                "https://your-domain.com/images/news.png"
        );

        return "所有类型消息已发送";
    }


    @GetMapping("/group/send/message")
    public String groupSendMessage() {
        wxWrokDomainService.sendMessageToChat("wrhjJVKwAA0O7CQJ76aEBF24dF0Yl0BA", "技术部的各位同事，这是一条推送的过来的测试消息。");
        return "Message sent successfully";
    }

    @GetMapping("/group/robot/txt/message")
    public String groupRobotSendTxtMessage() {
        //String[] userids = new String[]{"lidong","zhouzhong"};
        String[] mobiles = new String[]{"18871707887", "18727283863", "17771704470"};
        wxWrokDomainService.sendTxtMessageFromRobotToGroup(REBOT_WEB_HOOK, "技术部的各位同事，这是一条推送的过来的测试消息。", null, mobiles);
        return "Message sent successfully";
    }


    @GetMapping("/group/list")
    public String groupList() {
        wxWrokDomainService.getChatIdFromGroupChat();
        return "Message sent successfully";
    }

    @GetMapping("group/create")
    public String groupCreate() {
        wxWrokDomainService.createGroupChat("技术部", "Lidong");
        return "GroupChat created successfully";
    }

}
